#include "Level.h"

/* Defualt constructor */
Level::Level(){
    init();
    }

/* Initialize the playfield and the start values */
void Level::init(){
    //Initialize the playfield
    _playfield.resize(LVL_WIDTH * LVL_HEIGHT);
    //Make sure, the field is empty at start
    for (unsigned int i = 0; i < _playfield.size(); i++){
        _playfield[i] = EMPTY;
        }
    }

/* Returns what is located at a certain position */
unsigned int Level::getPosition(unsigned int x, unsigned int y){
    //cout << ((y*LVL_WIDTH)+x) << "\r\n"; //<- DEBUG
    return _playfield[(y*LVL_WIDTH)+x];
    }

/* Returns the playfield in a string representation */
string Level::getPlayfieldInString(){
    string field = "";
    for (int y = LVL_HEIGHT-1; y > -1; y--){
        for (unsigned int x = 0; x < LVL_WIDTH; x++){
            //Put the value into the string
            field += toString(getPosition(x,y));
            }
        field += "\n";    //\r\n for Windows, \n for Unix
        }
    return field;
    }

/* Set an element on a certain position */
void Level::setPosition(unsigned x, unsigned y, elements element){
    _playfield[(y*LVL_WIDTH)+x] = element;
    }

